﻿#include "publicshare.h"
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QApplication>
#include <QCoreApplication>

#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonParseError>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QVBoxLayout>

PublicShared::PublicShared()
{

}

QString PublicShared::readFileStr(const QString &iFilePath)
{
    QFile file(iFilePath);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
        return "";
    }

    QTextStream in(&file);

    QString str = in.readAll();

    file.close();
    return str;
}

bool PublicShared::writeFileStr(const QString &iFileName,const QString &iStr)
{
    QFile file(iFileName);

    if(file.open(QFile::WriteOnly|QFile::Truncate)){
        QTextStream stream(&file);
        stream << iStr;

        return true;
    }
    return false;
}

QVariant PublicShared::jsonStr2Variant(const QString &iStr)
{
    QJsonParseError error;
    const QJsonDocument &docment = QJsonDocument::fromJson(iStr.toUtf8(),&error);

    if(QJsonParseError::NoError == error.error){
        const QJsonObject &jsonObj = docment.object();
        QVariant value = QVariant::fromValue(jsonObj);
        return value;

    }else{
        return QVariant();
    }
}

QString PublicShared::variant2JsonStr(const QVariant &iValue)
{
    if(iValue.type() == QVariant::String){
        return iValue.toString();
    }
    QString str = QJsonDocument::fromVariant(iValue).toJson(QJsonDocument::Indented);
    return str;
}

void PublicShared::setStyle(const QString &styleFilePath)
{
    qApp->setStyleSheet(readFileStr(styleFilePath));
}

HoverCenterWgtAbs::HoverCenterWgtAbs(QVariantMap iDataMap, QWidget *iParent):QWidget(iParent),mDataMap(iDataMap)
{
    initUi();
}

HoverCenterWgtAbs::~HoverCenterWgtAbs()
{

}

void HoverCenterWgtAbs::initUi()
{

}
